package com.muyu.system.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoShoppingCategory;
import com.muyu.system.service.IDanmoShoppingCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 商品分类Controller
 *
 * @author yangle
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/category")
public class DanmoShoppingCategoryController extends BaseController
{
    @Autowired
    private IDanmoShoppingCategoryService danmoShoppingCategoryService;

    /**
     * 查询商品分类列表
     */
//    @RequiresPermissions("system:category:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoShoppingCategory danmoShoppingCategory)
    {
        List<DanmoShoppingCategory> list = danmoShoppingCategoryService.selectDanmoShoppingCategoryList(danmoShoppingCategory);
        return Result.success(list);
    }

    /**
     * 导出商品分类列表
     */
//    @RequiresPermissions("system:category:export")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoShoppingCategory danmoShoppingCategory)
    {
        List<DanmoShoppingCategory> list = danmoShoppingCategoryService.selectDanmoShoppingCategoryList(danmoShoppingCategory);
        ExcelUtil<DanmoShoppingCategory> util = new ExcelUtil<DanmoShoppingCategory>(DanmoShoppingCategory.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
//    @RequiresPermissions("system:category:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoShoppingCategoryService.selectDanmoShoppingCategoryById(id));
    }

    /**
     * 新增商品分类
     */
//    @RequiresPermissions("system:category:add")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoShoppingCategory danmoShoppingCategory)
    {
        return toAjax(danmoShoppingCategoryService.insertDanmoShoppingCategory(danmoShoppingCategory));
    }

    /**
     * 修改商品分类
     */
//    @RequiresPermissions("system:category:edit")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoShoppingCategory danmoShoppingCategory)
    {
        return toAjax(danmoShoppingCategoryService.updateDanmoShoppingCategory(danmoShoppingCategory));
    }

    /**
     * 删除商品分类
     */
//    @RequiresPermissions("system:category:remove")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoShoppingCategoryService.deleteDanmoShoppingCategoryByIds(ids));
    }
}
